#!/usr/local/bin/python3
# -*- coding: UTF-8 -*-
from Common.stringManage import *
from Common.splitSymbol import*
import time
import json
import os
import re
import sys
import shutil


# 将content写入Lua文件
def writeSymbolContentToLua(outputpath,content):
    indexLuaPath=outputpath+"/index.lua"
    fo=open(indexLuaPath,"w")
    fo.write(content)
    fo.close()

    metadataPath=outputpath+"/metadata.json"
    metadataContent="{\"script\" : \"index.lua\"}"
    fo=open(metadataPath,"w")
    fo.write(metadataContent)
    fo.close()

# 处理 <p1> 标签
def getSrcContent(filename, symbol):
    if os.path.exists(filename):
        return key_match(filename, symbol)
    else:
        if filename == "":
            return ""
        else:
            exit(0)
            print("该模板的配置文件不存在")

# 返回两个标签之间的内容
def key_match(path, symbol):
    endsymbol = "</"+getEndSymbol(symbol)+">"
    lines = 0
    with open(path, 'r') as f:
        buffser = f.read()
        # buffser = buffser.replace('\n', '')
        pattern = re.compile(symbol+'(.*?)'+endsymbol, re.S)
        result = pattern.findall(buffser)
        if result != []:
            # print(result)
            return str(result[0])
            #self.lines +=1
            # print("匹配到的行数：",self.lines)
        else:
            print("没有找到你输入的关键字")
